﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;

/// <summary>
/// Summary description for Paging
/// </summary>
public class CustomPaging
{
    PagedDataSource dsPage;
    static int _CurrentPageIndex = 0;
    static int _PageSize = 0;  //Default
    DataTable dt;

    public CustomPaging()
    {
        dsPage = new PagedDataSource();
    }


    /// <summary>
    /// Gets or Sets the PageIndex of a Control
    /// </summary>
    public int CurrentPageIndex
    {
        get
        {
            return _CurrentPageIndex;
        }
        set
        {
            _CurrentPageIndex = value;
        }
    }

    /// <summary>
    /// Gets or Sets the Page Size (Number of records per Page) of a Control
    /// </summary>
    public int PageSize
    {
        get
        {
            return _PageSize;
        }
        set
        {
            _PageSize = value;
        }
    }

    /// <summary>
    /// Gets or Sets the DataSource of a Control
    /// </summary>
    public DataTable DataSource
    {

        set
        {
            dt = new DataTable();
            dt = value;
        }
        get
        {
            return dt;
        }
    }

    /// <summary>
    /// Returns the corresponding true/false  if user is at the last Page
    /// </summary>
    public bool IsLastPage
    {
        get
        {
            return dsPage.IsLastPage;
        }
    }

    /// <summary>
    /// Returns the corresponding true/false  if user is at the first Page
    /// </summary>
    public bool IsFirstPage
    {
        get
        {
            return dsPage.IsFirstPage;
        }
    }

    /// <summary>
    /// Gets the Number of Pages available w.r.t Number of records in a control
    /// </summary>
    public int PageCount
    {
        get
        {
            return dsPage.PageCount;
        }
    }

    /// <summary>
    /// Implements the Page for a Control
    /// </summary>
    public PagedDataSource DoPaging
    {
        get
        {
            dsPage.AllowPaging = true;
            dsPage.PageSize = PageSize;
            dsPage.CurrentPageIndex = CurrentPageIndex;
            dsPage.DataSource = DataSource.DefaultView;

            return dsPage;
        }
    }
}
